package org.ala.tiktools.rpc.msg;

import java.io.Serializable;

/**
 * 消息头
 *
 * @author ala
 * @date 2025-04-04 17:37
 */
public class RpcMsgHead implements Serializable {
    public final static long serialVersionUID = 1;
    /**
     *  头长（16子节）
     */
    public final static int LENGTH = 16;


    /**
     *  消息id（8字节）
     *  <p> 雪花id算出
     */
    protected long id;
    /**
     *  消息类型（4字节）
     *  0:push | 1:ack | 2:ping | 3:pong | 4:login | 5:loginSuccess | 6:loginError | 7:loginNo
     */
    protected RpcMsgHeadTypeEnums type;
    /**
     *  消息体长度（4字节）
     */
    protected int len;


    public static RpcMsgHead build() {return new RpcMsgHead();}


    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public RpcMsgHead id(long id) {
        setId(id);
        return this;
    }

    public RpcMsgHeadTypeEnums getType() {
        return type;
    }

    public void setType(RpcMsgHeadTypeEnums type) {
        this.type = type;
    }

    public RpcMsgHead type(RpcMsgHeadTypeEnums type) {
        setType(type);
        return this;
    }

    public int getLen() {
        return len;
    }

    public void setLen(int len) {
        this.len = len;
    }

    public RpcMsgHead len(int len) {
        setLen(len);
        return this;
    }

    public String toString() {
        return String.format("{id:%d, type:%s, len:%d}", id, type, len);
    }
}
